package com.o2opuzi.lib.db;

import java.util.ArrayList;
import java.util.List;

public class Where {
	
	private List<String> sqls = new ArrayList<String>();
	
	private List<Object> params = new ArrayList<Object>();
	
	
	public Where eq(String name,Object...params){
		return addTerm(name+" = ?", params);
	}
	
	public Where eq(String name1,String name2,Object...params){
		return addTerm(name1+" = "+name2, params);
	}
	
	private Where addTerm(String name,Object...objects){
		sqls.add(" "+name);
		for (int i = 0; i < objects.length; i++) {
			params.add(objects[i]);
		}
		return this;
	}
	
	public String getSQLString(){
		int size =  sqls.size();
		String sql = "";
		for (int i = 0; i < size; i++) {
			if(size > 0){
				sql +=" and";
			}
			sql+=sqls.get(i);
		}
		return sql;
	}
	
	public Object[] getParams(){
		return this.params.toArray();
	}
	
	
}
